package com.walker.taogong.web;

import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.walker.taogong.bll.UserBll;
import com.walker.taogong.datamodel.User;

public class NewUser
{
    
    /** Logger. */
    private static Logger log = LoggerFactory.getLogger(NewUser.class);
    
    
    /************************ BLL 服务引用 *******************************************/
    
    private UserBll userBll;
    
    public void setUserBll(UserBll userBll)
    {
        this.userBll= userBll;
    }
    
    /*************************启动测试用************************************/
    /**
     * 组件启动初期化
     */
    protected void activate(ComponentContext cc) throws Exception
    {
        log.info("{} is starting!", cc.getProperties().get("name") );

        //主流程
        
        User user = new User();
        //1. 注册用户
        user.setUserName("lisi");
        user.setPassword("123456");
        
        //email或mobile任选其一
        user.setEmail("lisi@test.com") ;  //
        user.setMobile("13899991111")    ;   //optional
        
        
        if( userBll.createNewUser(user))
        {
            log.info("你已经成功注册完成:" + user.getUserName());
        }
        else
        {
            log.info("用户已经存在！");
        }
        
        if(userBll.login(user))
        {
            log.info(user.getUserName() + "已经成功登陆");
        }
        else
        {
            log.info("输入的用户信息不正，请重新输入");
        }
    }

}
